package ooboo.gui;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Image;

import javax.swing.ImageIcon;

public class Bubble
{
	private enum BubbleColor
	{
		WHITE,BLUE,GREEN;
	}
	
	public static final BubbleColor WHITE = BubbleColor.WHITE;
	public static final BubbleColor BLUE = BubbleColor.BLUE;
	public static final BubbleColor GREEN = BubbleColor.GREEN;
	
	
	private static final Image WHITE_BUBBLE = new ImageIcon("images/bubbles/white.png").getImage();
	private static final Image BLUE_BUBBLE = new ImageIcon("images/bubbles/blue.png").getImage();
	private static final Image GREEN_BUBBLE = new ImageIcon("images/bubbles/green.png").getImage();
	
	private static final Color WHITE_COLOR = new Color(233,233,233);
	private static final Color BLUE_COLOR = new Color(191,230,250);
	private static final Color GREEN_COLOR = new Color(225,246,205);
	

	public static void drawBubble(BubbleColor color,Graphics2D g2,int top,int right,int bottom,int left)
	{
		if(bottom - top < 30)
			bottom = top + 30;
		if(right - left < 30)
			right = left + 30;
		
		int innerTop = top + 20;
		int innerRight = right - 10;
		int innerBottom = bottom - 10;
		int innerLeft = left + 20;
		
		Image image;
		
		switch(color)
		{
		case GREEN:
			g2.setColor(GREEN_COLOR);
			image = GREEN_BUBBLE;
			break;
		case BLUE:
			g2.setColor(BLUE_COLOR);
			image = BLUE_BUBBLE;
			break;
		case WHITE:
		default:
			g2.setColor(WHITE_COLOR);
			image = WHITE_BUBBLE;
			break;
		}
		
		g2.drawImage(image,left,top,innerLeft,innerTop,0,0,20,20,null);
		g2.drawImage(image,innerRight,top,right,innerTop,22,0,32,20,null);
		g2.drawImage(image,left,innerBottom,innerLeft,bottom,0,22,20,32,null);
		g2.drawImage(image,innerRight,innerBottom,right,bottom,22,22,32,32,null);
		
		g2.drawImage(image,innerLeft,top,innerRight,innerTop,20,0,21,20,null);
		g2.drawImage(image,innerLeft,innerBottom,innerRight,bottom,20,22,21,32,null);
		g2.drawImage(image,left,innerTop,innerLeft,innerBottom,0,20,20,21,null);
		g2.drawImage(image,innerRight,innerTop,right,innerBottom,22,20,32,21,null);
		
		/*g2.drawImage(image,left,top,innerLeft,innerTop,0,0,20,20,null);
		g2.drawImage(image,innerRight,top,right,innerTop,44,0,64,20,null);
		g2.drawImage(image,left,innerBottom,innerLeft,bottom,0,54,20,64,null);
		g2.drawImage(image,innerRight,innerBottom,right,bottom,44,54,64,64,null);
		
		g2.drawImage(image,innerLeft,top,innerRight,innerTop,18,0,52,20,null);
		g2.drawImage(image,innerLeft,innerBottom,innerRight,bottom,18,54,52,64,null);
		g2.drawImage(image,left,innerTop,innerLeft,innerBottom,0,20,20,54,null);
		g2.drawImage(image,innerRight,innerTop,right,innerBottom,44,20,64,54,null);*/
		
		/*
		int x = 0;
		int width = innerRight - innerLeft;
		
		while(x <= width - 34)
		{
			g.drawImage(image,innerLeft + x,top,innerLeft + x + 34,innerTop,18,0,52,20,null);
			g.drawImage(image,innerLeft + x,innerBottom,innerLeft + x + 34,bottom,18,54,52,64,null);
			x += 34;
		}
		g.drawImage(image,innerLeft + x,top,innerRight,innerTop,
				18,0,18 + (width % 34),20,null);
		g.drawImage(image,innerLeft + x,innerBottom,innerRight,bottom,
				18,54,18 + (width % 34),64,null);
		
		
		int y = 0;
		int height = innerBottom - innerTop;
		
		while(y < height - 34)
		{
			g.drawImage(image,left,innerTop + y,innerLeft,innerTop + y + 34,0,20,20,54,null);
			g.drawImage(image,innerRight,innerTop + y,right,innerTop + y + 34,44,20,64,54,null);
			y += 34;
		}
		g.drawImage(image,left,innerTop + y,innerLeft,innerBottom,
				0,20,20,20 + (height % 34),null);
		g.drawImage(image,innerRight,innerTop + y,right,innerBottom,
				44,20,64,20 + (height % 34),null);
		*/
		
		//g2.setPaint(new GradientPaint(0,top + 8,new Color(255,255,255),0,bottom - top,new Color(200,200,200)));
		//g2.fillRoundRect(left + 15,top + 8,right - left,bottom - top - 16,10,10);
		//g2.setPaint(null);
		g2.fillRect(innerLeft,innerTop,innerRight - innerLeft,innerBottom - innerTop);
	}
	
	public static void drawReply(BubbleColor color,Graphics2D g2,int top,int right,int bottom,int left)
	{
		if(bottom - top < 30)
			bottom = top + 30;
		if(right - left < 30)
			right = left + 30;
		
		int innerTop = top + 20;
		int innerRight = right - 20;
		int innerBottom = bottom - 10;
		int innerLeft = left + 10;
		
		Image image;
		
		switch(color)
		{
		case GREEN:
			g2.setColor(GREEN_COLOR);
			image = GREEN_BUBBLE;
			break;
		case BLUE:
			g2.setColor(BLUE_COLOR);
			image = BLUE_BUBBLE;
			break;
		case WHITE:
		default:
			g2.setColor(WHITE_COLOR);
			image = WHITE_BUBBLE;
			break;
		}
		
		g2.drawImage(image,left,top,innerLeft,innerTop,32,0,22,20,null);
		g2.drawImage(image,innerRight,top,right,innerTop,20,0,0,20,null);
		g2.drawImage(image,left,innerBottom,innerLeft,bottom,32,22,22,32,null);
		g2.drawImage(image,innerRight,innerBottom,right,bottom,20,22,0,32,null);
		
		g2.drawImage(image,innerLeft,top,innerRight,innerTop,20,0,21,20,null);
		g2.drawImage(image,innerLeft,innerBottom,innerRight,bottom,20,22,21,32,null);
		g2.drawImage(image,left,innerTop,innerLeft,innerBottom,32,20,22,21,null);
		g2.drawImage(image,innerRight,innerTop,right,innerBottom,20,20,0,21,null);
		
		/*
		int x = 0;
		int width = innerRight - innerLeft;
		
		while(x <= width - 34)
		{
			g.drawImage(image,innerLeft + x,top,innerLeft + x + 34,innerTop,18,0,52,20,null);
			g.drawImage(image,innerLeft + x,innerBottom,innerLeft + x + 34,bottom,18,54,52,64,null);
			x += 34;
		}
		g.drawImage(image,innerLeft + x,top,innerRight,innerTop,
				18,0,18 + (width % 34),20,null);
		g.drawImage(image,innerLeft + x,innerBottom,innerRight,bottom,
				18,54,18 + (width % 34),64,null);
		
		
		int y = 0;
		int height = innerBottom - innerTop;
		
		while(y < height - 34)
		{
			g.drawImage(image,left,innerTop + y,innerLeft,innerTop + y + 34,64,20,44,54,null);
			g.drawImage(image,innerRight,innerTop + y,right,innerTop + y + 34,20,20,0,54,null);
			y += 34;
		}
		g.drawImage(image,left,innerTop + y,innerLeft,innerBottom,
				64,20,44,20 + (height % 34),null);
		g.drawImage(image,innerRight,innerTop + y,right,innerBottom,
				20,20,0,20 + (height % 34),null);
		*/
		g2.fillRect(innerLeft,innerTop,innerRight - innerLeft,innerBottom - innerTop);
	}
}
